﻿@{
	ViewBag.Title = "单位管理";
}

@section header {
	<style>
		.fast-filter .tablink {
			padding-right: 8px;
			padding-left: 2px;
		}
	</style>
}
@section quickmenu{
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="新建..." @@click="listAdd">
			<i class="icon-plus icon-2x pull-left icon-border crm-bu-style"></i>
		</span>
	</td>
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="查找..." @@click="searchToggle">
			<i class="icon-search icon-2x pull-left icon-border crm-bu-style"></i>
		</span>
	</td>
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="从Excel文件导入..." onclick="orgImportOpen();"><i class="icon-upload icon-2x pull-left icon-border crm-bu-style"></i></span>
	</td>
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="导出..." onclick="exportAll();"><i class="icon-download icon-2x pull-left icon-border crm-bu-style"></i></span>
	</td>
}

@*页面视图列表开始*@
<table class="list_table table100 fast-filter">
	<tbody>
		<tr>
			<td style="">
				<i class="icon-filter pure-icon-bu"></i>视图: 
				<span style="padding-right: 5px; ">
					&nbsp;&nbsp;<a class="cus_markbai tablink" href="javascript:void(0);">所有</a>&nbsp;&nbsp;
				</span>
				<span style="border-left: 2px solid #000; padding-left: 10px;">
					类型：<a class="tablink" :class="{'cus_markbai':!listConditions.type||listConditions.type=='0','cus_markhui':listConditions.type&&listConditions.type!='0'}" href="javascript:void(0);" @@click="listFastFilter($event)" data-ftype="reset" data-fname="type">不限</a>
					<a class="tablink" :class="{'cus_markbai':listConditions.type==w.value,'cus_markhui':listConditions.type!=w.value}" href="javascript:void(0);" v-for="(w,widx) in types" @@click="listFastFilter($event)" data-fname="type" :data-fvalue="w.value">{{w.text}}</a>
				</span>
			</td>
		</tr>
	</tbody>
</table>
@*页面视图列表结束*@
<form id="searchFrm">
	<div style="width:100%;overflow:auto;">
		<table style="width:100%;border-collapse:collapse;border:none;table-layout:fixed;">
			<tr>
				<td align="left" valign="top" style="width:18%;">
					<table class="small table100 padding3">
						<tr>
							<td class="dvtTabCache" style="width: 10px" nowrap>
								&nbsp;
							</td>
							<td class="tab-chan-link tab-chan-link-on" style="width: 100%; text-align: center;"
								nowrap>
								区域
							</td>
							<td class="dvtTabCache">
								&nbsp;
							</td>
						</tr>
					</table>
					<div id="areaTreeDiv" style="display: block; padding: 0 10px;">
						@*此处的最小高度与上面的一致*@
						<ul id="areaTree" class="ztree" style=""></ul>
					</div>
				</td>
				<td align="left" valign="top" style="border-left: 2px dashed #cccccc;width:85%;">
					<div id="searchDiv" style="z-index: 1; display: block; position: relative; margin-top: 3px;" v-show="searchShow">
						<table class="small table100" align="left">
							<tbody>
								<tr>
									<td class="small" nowrap="" align="left" style="padding-left: 10px;">
										<span>单位名称</span>
										<input type="text" class="txtBox" style="width: 150px" v-model.trim="listConditions.name">
										<span>单位编码</span>
										<input type="text" class="txtBox" style="width: 150px" v-model.trim="listConditions.code">
										<span>负责人</span>
										<input type="text" class="txtBox" style="width: 90px" v-model.trim="listConditions.chargeman">
										<span>负责人手机号</span>
										<input type="text" class="txtBox" style="width: 130px" v-model.trim="listConditions.chargemanphone">
										@*<span>状态</span>
											@Html.DropDownList("state", ViewBag.StateOptions as IEnumerable<SelectListItem>, "不限", new { v_model = "listConditions.state" })*@
										&nbsp;
										<button class="pure-button pure-button-edit" title="查找" @@click.prevent="listRefresh(1)">
											<i class="icon-search"></i>查找
										</button>
										&nbsp;
										<button class="pure-button pure-button-cancel" title="取消" @@click.prevent="searchReset">
											<i class="icon-rotate-left"></i>重置
										</button>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<table class="lvt small table100">
						<tr>
							<td style="" align="left" nowrap>
								<button class="pure-button pure-button-edit" @@click.prevent="listAdd">
									<i class="icon-plus"></i>&nbsp;新增
								</button>
								&nbsp;
								<button class="pure-button pure-button-danger" @@click.prevent="listBatchDelete">
									<i class="icon-trash"></i>&nbsp;批量删除
								</button>
								&nbsp;
								<button class="pure-button pure-button-share" onclick="togglePanelR(this,'divExport');return false;"
										onmouseout="hidePanel('divExport')">
									<i class="icon-download"></i>&nbsp;导出
								</button>
								&nbsp;
								<div id="divExport" class="list-bulk-div" onmouseout="hidePanel('divExport')" onmouseover="showPanel('divExport')">
									<div onclick="exportAll();">
										<i class="icon-download" style="padding: 0px 10px;"></i>导出全部
									</div>
									<div class="list-bulk-link" onclick="exportCurrent();">
										<i class="icon-cloud-download" style="padding: 0px 10px;"></i>导出当前页
									</div>
									<div onclick="exportSelected();">
										<i class="icon-download" style="padding: 0px 10px;"></i>导出选中
									</div>
								</div>
							</td>
							<td nowrap align="right" valign="middle">
								<table border="0" cellspacing="0" cellpadding="0" class="small">
									<tbody>
										<tr>
											<td style="padding-right: 5px">
												<vue-pagination :total="listData.total" :psize="listData.psize" :pnum="listData.pnum" @@change="pageChangeHandler"></vue-pagination>
											</td>
										</tr>
									</tbody>
								</table>
							</td>
						</tr>
					</table>
					<table class="crm-table table100 padding2" cellspacing="1" cellpadding="3">
						<caption v-show="listData.list.length==0">
							暂无数据
						</caption>
						<tr class="windLayerHead">
							<td style="width: 20px;">
								<input type="checkbox" name="selectall" @@click="listToggle($event)" v-model="listData.checked" />
							</td>
							<td v-for="(col,idx) in listColumns" :style="col.hdStyles">
								<a class='listFormHeaderLinks' @@click="listSort(col.name)" v-if="col.sort">{{col.title}}<i :class="{'icon-caret-up':listSortColumn.order=='asc','icon-caret-down':listSortColumn.order=='desc'}" v-if="col.name==listSortColumn.name"></i></a>
								<span v-else>{{col.title}}</span>
							</td>
							<td nowrap style="width: 120px;">
								操作
							</td>
						</tr>
						<tr v-for="(item,idx) in pageList" :rid="item.ID" :class="{'crm-table-plural':idx%2==1}" style="cursor: pointer;">
							<td>
								<input type="checkbox" name="rowid" :value='item.ID' :data-idx="idx" @@click="listCheck($event)" :checked="item.CheckedState" />
							</td>
							<td v-for="(col,cidx) in listColumns" :style="item.Styles[cidx]">
								<a :href="item.Links[cidx].href" v-if="item.Links[cidx].href">{{item[col.name]}}</a>
								<span v-else>{{item[col.name]}}</span>
							</td>
							<td nowrap>
								@*<i class="icon-edit pure-icon-bu crm-bu-style list-action-btn" title='班级管理' style="" @@click="listClassList(item)"></i>
									<i class="icon-edit pure-icon-bu crm-bu-style list-action-btn" title='学生管理' style="" @@click="listStudentList(item)"></i>*@
								<i class="icon-edit pure-icon-bu crm-bu-style list-action-btn" title='修改' style="" @@click="listEdit(item)"></i>
								<i class="icon-trash pure-icon-bu crm-bu-style list-action-btn" title='删除' style="" @@click="listDelete(item)"></i>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
</form>
@*生成列表操作*@
<div id="areaEditDiv" class="windLayerDiv" style="display: none;">
	<table class="windLayerHeadingULine table100" cellpadding="3" cellspacing="0">
		<tr class="windLayerHeadingTr">
			<td width="80%" style="cursor: move;" class="windLayerHeading" align="left">
				编辑区域信息
			</td>
			<td align="right">
				<input class="windLayerBtclose" type="button" title="关闭" onclick="areaClose();">&nbsp;&nbsp;
			</td>
		</tr>
	</table>
	<form id="areaEditFrm">
		<table style="background-color: rgb(234, 234, 234);width:100%;" class="small" border="0" cellpadding="3" cellspacing="1">
			<tr class="detail-content-heading" style="height: 28px;">
				<td colspan="2">
					<b>&nbsp;&nbsp;基本信息</b>
				</td>
			</tr>
			<tr bgcolor="white" height="25px;">
				<td class="windLayerTitle" align="right" width="30%;">
					<span style="color: #f00;">*</span>区域名称
				</td>
				<td class="windLayerInfo" align="left" width="70%;">
					<input type="text" v-model.trim="areaModel.Name" class="detailedViewTextBox validate[required]"
						   style="width: 90%;" />
				</td>
			</tr>
			<tr bgcolor="white" height="25px;">
				<td class="windLayerTitle" align="right">
					区域编号
				</td>
				<td class="windLayerInfo" align="left">
					<input type="text" v-model.trim="areaModel.Code" class="detailedViewTextBox" style="width: 90%;" />
				</td>
			</tr>
			<tr bgcolor="white" height="25px;">
				<td class="windLayerTitle" align="right">
					排序
				</td>
				<td class="windLayerInfo" align="left">
					<input type="number" v-model="areaModel.Sort" value="" class="detailedViewTextBox" style="width: 90%;" />
				</td>
			</tr>
			<tr bgcolor="white" height="40px;">
				<td colspan="2" align="center">
					<button type="button" class="pure-button pure-button-success save" onclick="$('#areaEditFrm').submit();">
						<i class="icon-check"></i>保存
					</button>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<button type="button" class="pure-button pure-button-cancel" onclick="areaClose();return false;">
						<i class="icon-reply"></i>取消
					</button>
					&nbsp;
				</td>
			</tr>
		</table>
	</form>
	<div class="windLayerFoot">
		&nbsp;
	</div>
	<div class="windLayerCorner">
		&nbsp;
	</div>
</div>
@section footer{
	@*日期必须开始*@
	<script src="~/lib/laydate/laydate.js" asp-append-version="true"></script>
	@*日期必须结束*@
	@*验证开始*@
	<script src="~/lib/validationEngine/jquery.validationEngine.min.js" asp-append-version="true"></script>
	<script src="~/lib/validationEngine/jquery.validationEngine-zh_CN.js" asp-append-version="true"></script>
	<link href="~/lib/validationEngine/validationEngine.jquery.css" rel="stylesheet" asp-append-version="true" />
	@*验证结束*@
	@*列表相关开始*@
	<script type="text/javascript">
		var listConditionsInit = { state: "",type:"0" };//初始查询条件
		var pageEnumData = {
			states: @(Json.Serialize(ViewBag.StateOptions)),
			types: @(Json.Serialize(ViewBag.TypeOptions)),
		};
		var pageData = {
			hideBreadcrumb: false,
			serviceCode: '@(ViewBag.ServiceCode)',
			global: globalData,
			types: pageEnumData.types,
			states: pageEnumData.states,
			listData: {
				checked:false,
				list: [],
				total: 0,
				pnum: 1,
				psize:20,
			},
			listColumns: [
				{
					title: "类型",
					name: "TypeName",
					hdStyles: {
						width: "80px",
					},
					bdStyles: {
					}
				},
				{
					title: "区域",
					name: "AreaName",
					hdStyles: {
						width: "80px",
					},
					bdStyles: {
					}
				},
				{
					title: "单位名称",
					name: "Name",
					sort: true,
					href:"@(Url.Action("ViewDetail", "Sys_Organization"))/{ID}",
					hdStyles: {
						width: "120px",
					},
					bdStyles: {
					}
				},
				{
					title: "单位编码",
					name: "Code",
					sort: true,
					href:"@(Url.Action("ViewDetail", "Sys_Organization"))/{ID}",
					hdStyles: {
						width: "160px",
					},
					bdStyles: {
					}
				},
				{
					title: "负责人",
					name: "ChargeMan",
					hdStyles: {
						width: "60px",
					},
					bdStyles: {
					}
				},
				{
					title: "负责人手机号",
					name: "ChargeManPhone",
					hdStyles: {
						width: "120px",
					},
					bdStyles: {
					}
				},
				{
					title: "详细地址",
					name: "DetailAddress",
					hdStyles: {
						width: "210px",
					},
					bdStyles: {
					}
				},
				{
					title: "电话",
					name: "Phone",
					hdStyles: {
						width: "75px",
					},
					bdStyles: {
					}
				},
				{
					title: "传真",
					name: "Fax",
					hdStyles: {
						width: "75px",
					},
					bdStyles: {
					}
				},
				{
					title: "创建时间",
					name: "AddDate",
					hdStyles: {
						width: "110px",
					},
					bdStyles: {
					}
				}
			],
			searchShow:true,
			listConditions: Object.assign({}, listConditionsInit),
			listSortColumn: {
				name: "",
				order:""
			},
			listStyles: {
				@*"StateNow": {
					"@((int)ST.Buz.Base.Enums.UserState.已注销)": {color:"#FF0000"},
					"@((int)ST.Buz.Base.Enums.UserState.已冻结)": {color:"#FFCC00"},
					"@((int)ST.Buz.Base.Enums.UserState.未授权)": {color:"#E2AF08"},
					"@((int)ST.Buz.Base.Enums.UserState.未激活)": {color:"#42c642"},
					"@((int)ST.Buz.Base.Enums.UserState.未绑定)": {color:"#1A93DF"},
				}*@
			},
			areaModel: {},
		};

		var pageApp = new Vue({
			el: '#app',
			data: pageData,
			mounted: function () {
				this.listConditions = Object.assign({},this.listConditions, utils.pageRestore());
				this.listRefresh();
			},
			methods: {
				pageChangeHandler: function (args) {
					this.listRefresh(args.pnum, args.psize)
				},
				listFastFilter: function (e) {
					var obj = e.srcElement || e.target;
					$(obj).parent('span').find('.tablink').removeClass('cus_markbai').addClass('cus_markhui');
					$(obj).addClass('cus_markbai');
					switch (obj.dataset.ftype) {
						case "date":
							{
								if (!obj.dataset.fstart || !obj.dataset.fend) {
									return;
								}
								var dts = '';
								var dte = '';
								switch (obj.dataset.fvalue) {
									case "nowd":
										dts = moment().startOf('day').format('YYYY-MM-DD');
										dte = moment().format('YYYY-MM-DD');
										break;
									case "noww":
										dts = moment().startOf('isoWeek').format('YYYY-MM-DD');
										dte = moment().format('YYYY-MM-DD');
										break;
									case "nowm":
										dts = moment().startOf('month').format('YYYY-MM-DD');
										dte = moment().format('YYYY-MM-DD');
										break;
									case "nowy":
										dts = moment().startOf('year').format('YYYY-MM-DD');
										dte = moment().format('YYYY-MM-DD');
										break;
									case "lastw":
										dts = moment().week(moment().week() - 1).startOf('isoWeek').format('YYYY-MM-DD');
										dte = moment().week(moment().week() - 1).endOf('isoWeek').format('YYYY-MM-DD');
										break;
									case "lastm":
										dts = moment().month(moment().month() - 1).startOf('month').format('YYYY-MM-DD');
										dte = moment().month(moment().month() - 1).endOf('month').format('YYYY-MM-DD');
										break;
								}
								var dates = {};
								dates[obj.dataset.fstart] = dts;
								dates[obj.dataset.fend] = dte;
								this.listConditions = Object.assign({}, this.listConditions, dates);
								this.listRefresh(1);
							}
							break;
						case "reset":
							{
								var values = {};
								if (obj.dataset.fname) {
									values[obj.dataset.fname] = obj.dataset.fvalue;
									this.listConditions = Object.assign({}, this.listConditions, values);
								} else if (obj.dataset.fstart && obj.dataset.fend) {
									values[obj.dataset.fstart] = '';
									values[obj.dataset.fend] = '';
									this.listConditions = Object.assign({}, this.listConditions, values);
								}
								this.listRefresh(1);
							}
							break;
						default:
							{
								if (!obj.dataset.fname) {
									return;
								}
								var values = {};
								values[obj.dataset.fname] = obj.dataset.fvalue;
								this.listConditions = Object.assign({}, this.listConditions, values);
								this.listRefresh(1);
							}
					}
				},
				listRefresh: function (pageNum, pageSize) {
					var _params = Object.assign({}, {
						pnum: pageNum || this.listData.pnum,
						psize: pageSize || this.listData.psize,
						sortorder: !this.listSortColumn.name ? "" : this.listSortColumn.name + "_" + this.listSortColumn.order
					}, this.listConditions);
					utils.pageStore(_params,pageNum,pageSize);
					var _this = this;
					utils.ajaxPost('@(Url.Action("Search", "Sys_Organization"))', _params, function (resp) {
						var list = resp.data.list.map(function (item) {
							return Object.assign({}, item, {
								CheckedState: false
							});
						});
						var newData = { list: list, total: resp.data.total, pnum: resp.data.pnum, psize: resp.data.psize ,checked:false};
						_this.listData = newData;
					}, function (err) {
					})
				},
				searchReset: function () {
					$('.fast-filter').find('.tablink[data-ftype="reset"]').each(function (idx, elem) {
						$(elem).parent('span').find('.tablink').removeClass('cus_markbai').addClass('cus_markhui');
						$(elem).removeClass('cus_markhui').addClass('cus_markbai');
					});
					this.listConditions = Object.assign({}, listConditionsInit);
					this.listSortColumn = {
						col: "",
						order: ""
					};
					this.listRefresh(1);
				},
				searchToggle: function () {
					this.searchShow = !this.searchShow;
				},
				listSort: function (col) {
					if (col != this.listSortColumn.name) {
						this.listSortColumn.order = "desc";
						this.listSortColumn.name = col;
					} else {
						this.listSortColumn.order = this.listSortColumn.order == "asc" ? "desc" : "asc";
					}
					this.listRefresh(1);
				},
				listToggle: function (e) {
					var checked = (e.srcElement || e.target).checked;
					this.listData.list=this.listData.list.map(function (item) {
						return Object.assign({}, item,{
							CheckedState: checked
						});
					});
				},
				listCheck: function (e) {
					var obj = e.srcElement || e.target;
					var checked = obj.checked;
					this.listData.list.splice(obj.dataset.idx, 1, Object.assign({}, this.listData.list[obj.dataset.idx], {
						CheckedState: checked
					}));
				},
				listAdd: function () {
					location.href = '@(Url.Action("Add","Sys_Organization"))';
				},
				listEdit: function (item) {
					location.href = '@(Url.Action("Edit","Sys_Organization"))/'+item.ID;
				},
				listClassList: function (item) {
					location.href = '@(Url.Action("List","PEIS_Class"))?orgid='+item.ID;
				},
				listStudentList: function (item) {
					location.href = '@(Url.Action("List","PEIS_Student"))?orgid='+item.ID;
				},
				listDelete: function (item) {
					var _this = this;
					utils.confirm('确定要删除单位【' + item.Name +'】？', function () {
						utils.ajaxPost('@(Url.Action("Delete","Sys_Organization"))', { id: item.ID }, function (resp) {
							utils.success("删除成功");
							_this.listRefresh();
						}, function (msg) {
							utils.alert(msg);
						});
					});
				},
				listBatchDelete: function () {
					var selected = this.listData.list.filter(function (item) {
						return item.CheckedState;
					});
					var ids = selected.map(function (item) {
						return item.ID;
					});
					if (!ids||ids.length == 0) {
						utils.alert('请先选择要删除的单位');
						return;
					}
					var _this = this;
					utils.confirm('确定要删除所选择的单位？', function () {
						utils.ajaxPost('@(Url.Action("BatchDelete", "Sys_Organization"))',  ids , function (resp) {
							utils.success("删除成功");
							_this.listRefresh();
						}, function (msg) {
							utils.alert(msg);
						});
					});
				},
				saveCat: function () {
					var _this = this;
					utils.ajaxPost('@(Url.Action("Save", "Sys_Area"))', _this.areaModel, function (resp) {
						areaClose();
						areaRefresh();
						if (_this.areaModel.ID && _this.areaModel.ID > 0) {
							_this.listRefresh();
						}
					}, function (msg) {
						utils.alert(msg);
					});
				}
			},
			computed: {
				pageList: function () {
					var _this = this;
					return this.listData.list.map(function (item) {
						return Object.assign({}, item, {
							TypeName: _this.$options.filters.formatType(item.Type),
							DetailAddress: [item.Province, item.City, item.District, item.DetailAddress].join('-'),
							Styles: _this.listColumns.map(function (col) {
								return Object.assign({}, col.bdStyles, _this.listStyles[col.name] ? _this.listStyles[col.name][item[col.name]] : {})
							}),
							Links: _this.listColumns.map(function (col) {
								return Object.assign({}, { href: col.href ? col.href.replace(/{ID}/g, item.ID) : "" });
							}),
						});
					});
				},
				currentM: function () {
					var currentM = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentM = this.global.modules[i];
								break;
							}
						}
					}
					return currentM;
				},
				currentS: function () {
					var currentS = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentS = this.global.modules[i].Services[j];
								break;
							}
						}
					}
					return currentS;
				}
			},
			filters: {
				formatType: function (val) {
					return utils.formatEnum(val, pageEnumData.types);
				}
			}
		});
	</script>
	@*列表相关结束*@
	@*区域相关开始*@
	<link href="~/lib/ztree/ztree.css" rel="stylesheet" asp-append-version="true" />
	<script src="~/lib/ztree/ztree.core-3.5.37.min.js" asp-append-version="true"></script>
	<script src="~/lib/ztree/ztree.exedit-3.5.37.js" asp-append-version="true"></script>
	<script type="text/javascript">
		var areaSetting = {
			view: {
				addHoverDom: function(treeId, treeNode) {
					var sObj = $("#" + treeNode.tId + "_span");
					if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
					var addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增下级' onfocus='this.blur();'></span>";
					sObj.after(addStr);
					var btn = $("#addBtn_" + treeNode.tId);
					if (btn) btn.bind("click", function () {
						areaAdd(treeNode);
						return false;
					});
				},
				removeHoverDom: function (treeId, treeNode) {
					$("#addBtn_" + treeNode.tId).unbind().remove();
				},
				selectedMulti: false
			},
			edit: {
				enable: true,
				removeTitle: "删除",
				renameTitle: "修改"
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onClick: onTreeClick,
				onDblClick: onTreeDblClick,
				beforeDrag: onTreeBeforeDrag,
				beforeDrop: onTreeBeforeDrop,
				onDrop: onTreeDrop,
				beforeEditName: onTreeBeforeEditName,//修改事件
				beforeRemove: onTreeBeforeRemove,//删除事件
			}
		};

		function onTreeClick(event, treeId, treeNode, clickFlag) {
			pageApp.listConditions = Object.assign({}, pageApp.listConditions, {
				areaid: treeNode.id
			});
			pageApp.listRefresh(1);
		}

		function onTreeDblClick(event, treeId, treeNode, clickFlag) {
			areaEdit(treeNode);
		}

		function onTreeBeforeDrag(treeId, treeNodes) {
			if (!treeNodes[0].id || treeNodes[0].id=='0') {
				return false;
			}
		}

		function onTreeBeforeDrop(treeId, treeNodes, targetNode, moveType) {
			var canDrop = !(targetNode == null || (moveType != "inner" && !targetNode.parentTId));
			if (canDrop && (treeNodes[0].pId != targetNode.pId || moveType == "inner")) {
				return false;
			}
			return canDrop;
		}

		function onTreeDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
			if (!moveType || !targetNode) {
				return;
			}
			var ids = targetNode.getParentNode().children.map(function (item,idx) {
				return { id: item.id, order: idx };
			});
			utils.ajaxPost('@(Url.Action("SetOrder", "Sys_Area"))',  ids , function (resp) {
				areaRefresh();
			}, function (msg) {
				utils.alert(msg);
				areaRefresh();
			});

		}

		function onTreeBeforeEditName(treeId, treeNode) {
			areaEdit(treeNode);
			return false;
		}

		function onTreeBeforeRemove(treeId, treeNode) {
			utils.confirm('确定删除[' + treeNode.name + ']？', function () {
				utils.ajaxPost('@(Url.Action("Delete", "Sys_Area"))', { id: treeNode.id }, function (resp) {
					areaRefresh();
				}, function (msg) {
					utils.alert(msg);
				});
			});
			return false;
		}

		function areaRefresh() {
			utils.ajaxPost('@(Url.Action("GetZTreeData", "Sys_Area"))', {id:""}, function (resp) {
				$.fn.zTree.init($("#areaTree"), areaSetting, resp.data);
			});
		}

		var areaLayerIndex;
		function areaOpen() {
			areaLayerIndex=layer.open({
				type: 1,
				title: false,
				closeBtn: 0,
				area: '520px',
				skin: 'layui-layer-nobg', //没有背景色
				shadeClose: false,
				content: $('#areaEditDiv')
			});
		}

		function areaClose() {
			layer.close(areaLayerIndex|| layer.index);
		}

		function areaAdd(treeNode) {
			$('#areaEditDiv').find('.windLayerHeading').html('新增区域信息');
			pageApp.areaModel = {
				PID: treeNode.id,
				PName: !treeNode.id||treeNode.id=="0"?"":treeNode.name
			};
			areaOpen();
		}

		function areaEdit(treeNode) {
			if (!treeNode.id || treeNode.id == "0") {
				return;
			}
			utils.ajaxPost('@(Url.Action("ViewJson", "Sys_Area"))', { id: treeNode.id }, function (resp) {
				pageApp.areaModel = resp.data;
				areaOpen();
			}, function (msg) {
				utils.alert(msg);
			});
		}

		$(document).ready(function () {
			areaRefresh();
			$("#areaEditFrm").validationEngine({
				scroll: false,
				validateNonVisibleFields: false,
				autoHidePrompt: true,
				promptPosition:'topLeft',
				showOneMessage: true,
				ajaxFormValidationMethod: 'post',
				onValidationComplete: function (form, status) {
					if (!status) {
						return;
					}
					pageApp.saveCat();
				}
			});
		});
	</script>
	@*区域相关结束*@
	@*导出相关开始*@
	<script type="text/javascript">
		function orgImportOpen() {
			var uploadurl = '@(Url.Action("ImportExcel", "Sys_Organization"))';
			layer.open({
				type: 2,
				title: '单位信息导入',
				shadeClose: false,
				shade: [0.3, '#000'],
				//maxmin: true, //开启最大化最小化按钮
				area: ['800px', '380px'],
				content: uploadurl + (uploadurl.indexOf('?') < 0 ? '?' : '&') + 'callback=orgImportCallback&nc=' + new Date().getTime()
			});
		}

		function orgImportCallback() {
			pageApp.listRefresh(1);
			areaRefresh();
		}

		function getSelectedIDs() {
			var selected = pageApp.listData.list.filter(function (item) {
				return item.CheckedState;
			});
			var ids = selected.map(function (item) {
				return item.ID;
			});
			return ids;
		}

		function getCurrentPageIDs() {
			var ids = pageApp.listData.list.map(function (item) {
				return item.ID;
			});
			return ids;
		}
	</script>
	@*导出相关结束*@
}